<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>RabbitMQ总结 | Jeremy Sze的博客</title>
    <meta property="og:title" content="RabbitMQ总结 - Jeremy Sze的博客">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2018-11-07T08:36:54&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2018-11-07T08:36:54&#43;08:00'>
        
    <meta name="Keywords" content="java,博客">
    <meta name="description" content="RabbitMQ总结">
        
    <meta name="author" content="Jeremy Sze">
    <meta property="og:url" content="https://laoer123.gitee.io/laoer123/post/RabbitMQ%E6%80%BB%E7%BB%93/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href='/laoer123/css/normalize.css'>
    <link rel="stylesheet" href='/laoer123/css/style.css'>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({
        google_ad_client: "ca-pub-4031353640611810",
        enable_page_level_ads: true
    });
    </script>
    


    
    
        <link rel="stylesheet" href='/laoer123/css/douban.css'>
    
        <link rel="stylesheet" href='/laoer123/css/other.css'>
    
</head>


<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://laoer123.gitee.io/laoer123">
                        Jeremy Sze的博客
                    </a>
                
                <p class="description">专注于Java、JavaScript、软件开发、web开发、分布式，微服务系统开发</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://laoer123.gitee.io/laoer123">首页</a>
                    
                    <a  href="https://laoer123.gitee.io/laoer123/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#rabbitmq-简介">RabbitMQ 简介</a>
      <ul>
        <li><a href="#消息队列中间件简介">消息队列中间件简介</a></li>
      </ul>
    </li>
    <li><a href="#什么是-rabbitmq">什么是 RabbitMQ</a></li>
    <li><a href="#具体特点包括">具体特点包括：</a>
      <ul>
        <li><a href="#可靠性reliability">可靠性（Reliability）</a></li>
        <li><a href="#灵活的路由flexible-routing">灵活的路由（Flexible Routing）</a></li>
        <li><a href="#消息集群clustering">消息集群（Clustering）</a></li>
        <li><a href="#高可用highly-available-queues">高可用（Highly Available Queues）</a></li>
        <li><a href="#多种协议multi-protocol">多种协议（Multi-protocol）</a></li>
        <li><a href="#多语言客户端many-clients">多语言客户端（Many Clients）</a></li>
        <li><a href="#管理界面management-ui">管理界面（Management UI）</a></li>
        <li><a href="#跟踪机制tracing">跟踪机制（Tracing）</a></li>
      </ul>
    </li>
    <li><a href="#架构图和主要概念">架构图和主要概念</a></li>
    <li><a href="#主要概念">主要概念</a>
      <ul>
        <li><a href="#rabbitmq-server">RabbitMQ Server：</a></li>
        <li><a href="#producer">Producer：</a></li>
        <li><a href="#consumer">Consumer：</a></li>
        <li><a href="#exchange">Exchange：</a></li>
        <li><a href="#queue队列">Queue：（队列）</a></li>
        <li><a href="#routingkey">RoutingKey：</a></li>
        <li><a href="#connection连接">Connection：（连接）</a></li>
        <li><a href="#channels信道">Channels：（信道）：</a></li>
        <li><a href="#virtualhost">VirtualHost：</a></li>
      </ul>
    </li>
    <li><a href="#rabbitmq-安装与启动">RabbitMQ 安装与启动</a>
      <ul>
        <li><a href="#window-安装">window 安装</a></li>
      </ul>
    </li>
    <li><a href="#docker-安装">docker 安装</a></li>
    <li><a href="#直接模式direct">直接模式（Direct）</a>
      <ul>
        <li><a href="#什么是-direct-模式">什么是 Direct 模式</a></li>
      </ul>
    </li>
    <li><a href="#创建队列">创建队列</a></li>
    <li><a href="#代码实现-消息生产者">代码实现-消息生产者</a></li>
    <li><a href="#分列模式fanout">分列模式（Fanout）</a></li>
    <li><a href="#交换器绑定队列">交换器绑定队列</a></li>
    <li><a href="#主题模式topic">主题模式（Topic）</a></li>
    <li><a href="#创建队列与绑定">创建队列与绑定</a></li>
    <li><a href="#使用阿里云大于发送短信">使用阿里云大于发送短信</a>
      <ul>
        <li><a href="#阿里大于简介">阿里大于简介</a></li>
      </ul>
    </li>
    <li><a href="#准备工作">准备工作</a>
      <ul>
        <li><a href="#注册账户">注册账户</a></li>
      </ul>
    </li>
    <li><a href="#创建accesskeys">创建accesskeys</a></li>
    <li><a href="#下载sdk及demo">下载SDK及DEMO</a></li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">RabbitMQ总结</h1>
        </header>
        <date class="post-meta meta-date">
            2018年11月7日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='https://laoer123.gitee.io/categories/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6'>消息中间件</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <h2 id="rabbitmq-简介">RabbitMQ 简介</h2>
<h3 id="消息队列中间件简介">消息队列中间件简介</h3>
<p>  消息队列中间件是分布式系统中重要的组件，$\color{red}{主要解决应用耦合，异步消息，流量削锋等问
题实现高性能，高可用，可伸缩和最终一致性[架构] }$使用较多的消息队列有 ActiveMQ，
RabbitMQ，ZeroMQ，Kafka，MetaMQ，RocketMQ(基于Kafka，由阿里研发)
以下介绍消息队列在实际应用中常用的使用场景：$\color{red}{异步处理，应用解耦，流量削锋和消息通讯四个场景}$</p>
<h2 id="什么是-rabbitmq">什么是 RabbitMQ</h2>
<p>  RabbitMQ 是一个由 Erlang 语言开发的 AMQP 的开源实现。<br>
AMQP ：Advanced Message Queue，高级消息队列协议。它是应用层协议的一个开放标准，
为面向消息的中间件设计，基于此协议的客户端与消息中间件可传递消息，并不受产品、开
发语言等条件的限制。<br>
  RabbitMQ 最初起源于金融系统，用于在分布式系统中存储转发消息，在易用性、扩展性、
高可用性等方面表现不俗。</p>
<h2 id="具体特点包括">具体特点包括：</h2>
<h3 id="可靠性reliability">可靠性（Reliability）</h3>
<p>RabbitMQ 使用一些机制来保证可靠性，如$\color{green}{持久化、传输确认、发布确认。}$</p>
<h3 id="灵活的路由flexible-routing">灵活的路由（Flexible Routing）</h3>
<p>在消息进入队列之前，通过 Exchange 来路由消息的。对于典型的路由功能，RabbitMQ 已
经提供了一些内置的 Exchange 来实现。针对更复杂的路由功能，可以将多个 Exchange 绑
定在一起，也通过插件机制实现自己的 Exchange 。</p>
<h3 id="消息集群clustering">消息集群（Clustering）</h3>
<p>多个 RabbitMQ 服务器可以组成一个集群，形成一个逻辑 Broker 。</p>
<h3 id="高可用highly-available-queues">高可用（Highly Available Queues）</h3>
<p>队列可以在集群中的机器上进行镜像，使得在部分节点出问题的情况下队列仍然可用。</p>
<h3 id="多种协议multi-protocol">多种协议（Multi-protocol）</h3>
<p>RabbitMQ 支持多种消息队列协议，比如$\color{green}{ STOMP、MQTT 等等。}$</p>
<h3 id="多语言客户端many-clients">多语言客户端（Many Clients）</h3>
<p>RabbitMQ 几乎支持所有常用语言，比如 Java、.NET、Ruby 等等。</p>
<h3 id="管理界面management-ui">管理界面（Management UI）</h3>
<p>RabbitMQ 提供了一个易用的用户界面，使得用户可以监控和管理消息 Broker 的许多方面。</p>
<h3 id="跟踪机制tracing">跟踪机制（Tracing）</h3>
<p>如果消息异常，RabbitMQ 提供了消息跟踪机制，使用者可以找出发生了什么。</p>
<h4 id="插件机制plugin-system">插件机制（Plugin System）</h4>
<p>RabbitMQ 提供了许多插件，来从多方面进行扩展，也可以编写自己的插件</p>
<h2 id="架构图和主要概念">架构图和主要概念</h2>
<p><img src="/img/rabbitMQ%E6%9E%B6%E6%9E%84%E5%9B%BE.png" alt="alt rabbitMQ架构图"></p>
<h2 id="主要概念">主要概念</h2>
<h3 id="rabbitmq-server">RabbitMQ Server：</h3>
<p>也叫 broker server，它是一种传输服务。 他的角色就是维护一条从
Producer 到 Consumer 的路线，保证数据能够按照指定的方式进行传输。</p>
<h3 id="producer">Producer：</h3>
<p>消息生产者，如上图 A、B、C，数据的发送方。消息生产者连接 RabbitMQ 服务器
然后将消息投递到 Exchange。</p>
<h3 id="consumer">Consumer：</h3>
<p>消息消费者，如上图 1、2、3，数据的接收方。消息消费者订阅队列，RabbitMQ 将 Queue 中的消息发送到消息消费者。</p>
<h3 id="exchange">Exchange：</h3>
<p>生产者将消息发送到 Exchange（交换器），由 Exchange 将消息路由到一个或多
个 Queue 中（或者丢弃）。Exchange 并不存储消息。RabbitMQ 中的 Exchange 有$\color{red}{ direct(直连)、fanout(分裂)、
topic(主题)、headers(头) 四种类型，每种类型对应不同的路由规则。}$</p>
<h3 id="queue队列">Queue：（队列）</h3>
<p>是 RabbitMQ 的内部对象，用于存储消息。消息消费者就是通过订阅队列
来获取消息的，RabbitMQ 中的消息都只能存储在 Queue 中，生产者生产消息并最终投递到
Queue 中，消费者可以从 Queue 中获取消息并消费。多个消费者可以订阅同一个 Queue，
这时 Queue 中的消息会被平均分摊给多个消费者进行处理，而不是每个消费者都收到所有
的消息并处理。(使用轮循的方式获得消息)</p>
<h3 id="routingkey">RoutingKey：</h3>
<p>$\color{red}{生产者在将消息发送给 Exchange 的时候，一般会指定一个 routing key，来指定
这个消息的路由规则，而这个 routing key 需要与 Exchange Type 及 binding key 联合使用才能
最终生效。}$在 Exchange Type 与 binding key 固定的情况下（在正常使用时一般这些内容都是
固定配置好的），$\color{green}{我们的生产者就可以在发送消息给 Exchange 时，通过指定 routing key 来
决定消息流向哪里。(就是一种匹配规则)}$RabbitMQ 为 routing key 设定的长度限制为 255bytes。</p>
<h3 id="connection连接">Connection：（连接）</h3>
<p>Producer 和 Consumer 都是通过 TCP 连接到 RabbitMQ Server
的。以后我们可以看到，程序的起始处就是建立这个 TCP 连接。</p>
<h3 id="channels信道">Channels：（信道）：</h3>
<p>它建立在上述的 TCP 连接中。数据流动都是在 Channel 中进行的。也
就是说，$\color{red}{一般情况是程序起始建立 TCP 连接，第二步就是建立这个 Channel。}$</p>
<h3 id="virtualhost">VirtualHost：</h3>
<p>权限控制的基本单位，一个 VirtualHost 里面有若干 Exchange 和MessageQueue，以及指定被哪些 user 使用</p>
<h2 id="rabbitmq-安装与启动">RabbitMQ 安装与启动</h2>
<h3 id="window-安装">window 安装</h3>
<p>下载并安装 Eralng，以管理员身份运行安装）<br>
下载并安装 rabbitmq，注意不要安装在包含中文和空格的目录下！安装后 window 服务中就存在 rabbitMQ 了，并且是启动状态。<br>
安装管理界面（插件）<br>
需要重启电脑，再重新启动服务<br>
进入 rabbitMQ 安装目录的 sbin 目录，输入命令</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-txt" data-lang="txt">rabbitmq‐plugins enable rabbitmq_management  
</code></pre></td></tr></table>
</div>
</div><p>打开浏览器，地址栏输入 http://127.0.0.1:15672 ,即可看到管理界面的登陆页
<img src="/img/rabbitMQ%E6%9C%8D%E5%8A%A1%E7%AB%AFUI.png" alt="alt rabbitMQ服务端UI">
输入用户名和密码，都为 guest 进入主界面<br>
<img src="/img/rabbitMQ%E6%9C%8D%E5%8A%A1%E7%AB%AFUI1.png" alt="alt rabbitMQ服务端UI1">
最上侧的导航以此是：概览、连接、信道、交换器、队列、用户管理</p>
<h2 id="docker-安装">docker 安装</h2>
<p>下载镜像：</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-txt" data-lang="txt">docker pull rabbitmq:management
</code></pre></td></tr></table>
</div>
</div><p>创建容器，rabbitmq 需要有映射以下端口:</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-txt" data-lang="txt">5671 5672 4369 15671 15672 25672

 15672 (if management plugin is enabled)
 15671 management 监听端口
 5672, 5671 (AMQP 0-9-1 without and with TLS)
 4369 (epmd) epmd 代表 Erlang 端口映射守护进程
 25672 (Erlang distribution)
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-txt" data-lang="txt">docker run -di --name=myRabbitmq -p 5671:5617 -p 5672:5672 -p
4369:4369 -p 15671:15671 -p 15672:15672 -p 25672:25672 rabbitmq:management
</code></pre></td></tr></table>
</div>
</div><p>浏览器访问 http://192.168.2.2:15672/#/</p>
<h2 id="直接模式direct">直接模式（Direct）</h2>
<h3 id="什么是-direct-模式">什么是 Direct 模式</h3>
<p>我们需要将消息发给唯一一个节点时使用这种模式，这是最简单的一种形式。
<img src="/img/%E7%9B%B4%E8%BF%9E%E6%A8%A1%E5%BC%8F.png" alt="alt 直连模式">
任何发送到 Direct Exchange 的消息都会被转发到 RouteKey 中指定的 Queue。<br>
1.一般情况可以使用 rabbitMQ 自带的 Exchange：”&quot;(该 Exchange 的名字为空字符串，下文称其为 default Exchange)。<br>
2.这种模式下不需要将 Exchange 进行任何绑定(binding)操作<br>
3.消息传递时需要一个“RouteKey”，可以简单的理解为要发送到的队列名字。<br>
4.如果 vhost 中不存在 RouteKey 中指定的队列名，则该消息会被抛弃。</p>
<h2 id="创建队列">创建队列</h2>
<p>做下面的例子前，我们先建立一个叫 itcast 的队列。
<img src="/img/%E5%88%9B%E5%BB%BA%E9%98%9F%E5%88%97.png" alt="alt 创建队列">
Durability：是否做持久化 Durable（持久） transient（临时）<br>
Auto delete : 是否自动删除</p>
<h2 id="代码实现-消息生产者">代码实现-消息生产者</h2>
<p>导入依赖</p>
<pre><code class="language-pom" data-lang="pom">    &lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;2.0.1.RELEASE&lt;/version&gt;
        &lt;relativePath/&gt;
    &lt;/parent&gt;
    &lt;properties&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
        &lt;java.version&gt;1.8&lt;/java.version&gt;
    &lt;/properties&gt;
    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-amqp&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
</code></pre><p>配置文件 application.yml</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yml" data-lang="yml"><span style="color:#000;font-weight:bold">server</span>:<span style="color:#bbb">
</span><span style="color:#bbb">  </span><span style="color:#000;font-weight:bold">port</span>:<span style="color:#bbb"> </span><span style="color:#099">9204</span><span style="color:#bbb">
</span><span style="color:#bbb"></span><span style="color:#000;font-weight:bold">spring</span>:<span style="color:#bbb">
</span><span style="color:#bbb">  </span><span style="color:#000;font-weight:bold">rabbitmq</span>:<span style="color:#bbb">
</span><span style="color:#bbb">    </span><span style="color:#000;font-weight:bold">host</span>:<span style="color:#bbb"> </span><span style="color:#099">127.0.0.1</span><span style="color:#bbb">
</span></code></pre></td></tr></table>
</div>
</div><p>启动器</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@SpringBootApplication</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">Application</span> <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">main</span><span style="color:#000;font-weight:bold">(</span>String<span style="color:#000;font-weight:bold">[]</span> args<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        SpringApplication<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">run</span><span style="color:#000;font-weight:bold">(</span>Application<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">class</span><span style="color:#000;font-weight:bold">,</span>args<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>测试类===生产者</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@RunWith</span><span style="color:#000;font-weight:bold">(</span>SpringRunner<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">class</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#3c5d5d;font-weight:bold">@SpringBootTest</span><span style="color:#000;font-weight:bold">(</span>classes <span style="color:#000;font-weight:bold">=</span> Application<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">class</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">MqTest</span> <span style="color:#000;font-weight:bold">{</span>

    <span style="color:#3c5d5d;font-weight:bold">@Autowired</span>
<span style="color:#000;font-weight:bold">private</span> RabbitTemplate rabbitTemplate<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">directTest</span><span style="color:#000;font-weight:bold">(){</span>

        rabbitTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">convertAndSend</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JeremyDirect&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;直连模式&#34;</span><span style="color:#000;font-weight:bold">);</span>

    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>消费者</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@Component</span>
<span style="color:#3c5d5d;font-weight:bold">@RabbitListener</span><span style="color:#000;font-weight:bold">(</span>queues <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;JeremyDirect&#34;</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">Consumer1</span> <span style="color:#000;font-weight:bold">{</span>

    <span style="color:#3c5d5d;font-weight:bold">@RabbitHandler</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">sendMessage</span><span style="color:#000;font-weight:bold">(</span>String mes<span style="color:#000;font-weight:bold">){</span>

        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;接受到消息:&#34;</span><span style="color:#000;font-weight:bold">+</span>mes<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>

<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>修改服务端口，同时运行多个程序，会发现RabbitMQ采用轮询的方式，进行消费，这样的好处，能够平均的获得消息，并不会随机，导致有的很多，有的基本没有</p>
<h2 id="分列模式fanout">分列模式（Fanout）</h2>
<p>当我们需要将消息一次发给多个队列时，需要使用这种模式。如下图：
<img src="/img/RabbitMQ%E5%88%86%E8%A3%82%E6%A8%A1%E5%BC%8F.png" alt="alt RabbitMQ分裂模式">
任何发送到 Fanout Exchange 的消息都会被转发到与该 Exchange 绑定(Binding)的所有Queue 上。
1.可以理解为路由表的模式<br>
2.这种模式不需要 RouteKey<br>
3.这种模式需要提前将 Exchange 与 Queue 进行绑定，一个 Exchange 可以绑定多个Queue，一个 Queue 可以同多个 Exchange 进行绑定。<br>
4.如果接受到消息的 Exchange 没有与任何 Queue 绑定，则消息会被抛弃 。</p>
<h2 id="交换器绑定队列">交换器绑定队列</h2>
<p>创建多两个队列
<img src="/img/%E5%88%9B%E5%BB%BA%E9%98%9F%E5%88%971.png" alt="alt 创建队列1">
创建一个交换器
<img src="/img/%E5%88%9B%E5%BB%BA%E5%A4%9A%E4%B8%80%E4%B8%AA%E4%BA%A4%E6%8D%A2%E5%99%A8.png" alt="alt 创建多一个交换器">
交换器绑定队列
<img src="/img/%E4%BA%A4%E6%8D%A2%E5%99%A8%E7%BB%91%E5%AE%9A%E9%98%9F%E5%88%97.png" alt="alt 交换器绑定队列">
代码实现</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 分列模式
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">FanoutTest</span><span style="color:#000;font-weight:bold">(){</span>
        rabbitTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">convertAndSend</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JeremyFanout&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;分列模式&#34;</span><span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>消费者1</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#000;font-weight:bold">*/</span>
<span style="color:#3c5d5d;font-weight:bold">@Component</span>
<span style="color:#3c5d5d;font-weight:bold">@RabbitListener</span><span style="color:#000;font-weight:bold">(</span>queues <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;JeremyFanout&#34;</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">ConsumerFanout</span> <span style="color:#000;font-weight:bold">{</span>


    <span style="color:#3c5d5d;font-weight:bold">@RabbitHandler</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">JeremyFanoutTest</span><span style="color:#000;font-weight:bold">(</span>String msg<span style="color:#000;font-weight:bold">){</span>

        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JeremyFanout:&#34;</span><span style="color:#000;font-weight:bold">+</span>msg<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>消费者2</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@Component</span>
<span style="color:#3c5d5d;font-weight:bold">@RabbitListener</span><span style="color:#000;font-weight:bold">(</span>queues <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;JeremyFanout1&#34;</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">ConsumerFanout1</span> <span style="color:#000;font-weight:bold">{</span>

    <span style="color:#3c5d5d;font-weight:bold">@RabbitHandler</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">JeremyFanout1Test</span><span style="color:#000;font-weight:bold">(</span>String msg<span style="color:#000;font-weight:bold">){</span>

        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JeremyFanout1:&#34;</span><span style="color:#000;font-weight:bold">+</span>msg<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="主题模式topic">主题模式（Topic）</h2>
<p>任何发送到 Topic Exchange 的消息都会被转发到所有关心 RouteKey 中指定话题的 Queue 上
<img src="/img/%E4%B8%BB%E9%A2%98%E6%A8%A1%E5%BC%8F.png" alt="alt 主题模式">
如上图所示<br>
  此类交换器使得来自不同的源头的消息可以到达一个对列，其实说的更明白一点就是模
糊匹配的意思。<br>
例如：上图中红色对列的 routekey 为 usa.#，#代表匹配任意字符，但是要想消息能到达此对列，usa.必须匹配后面的#好可以随意。图中 usa.news
usa.weather,都能找到红色队列，符号 # 匹配一个或多个词。<br>
符号 * 匹配不多不少一个词。因此 usa.# 能够匹配到 usa.news.XXX ，但是 usa.* 只会匹配到 usa.XXX 。<br>
注：<br>
  交换器说到底是一个名称与队列绑定的列表。当消息发布到交换器时，实际上是由你所
连接的信道，将消息路由键同交换器上绑定的列表进行比较，最后路由消息。<br>
  任何发送到 Topic Exchange 的消息都会被转发到所有关心 RouteKey 中指定话题的Queue 上</p>
<ol>
<li>
<p>这种模式较为复杂，简单来说，就是每个队列都有其关心的主题，所有的消息都带有一
个“标题”(RouteKey)，Exchange 会将消息转发到所有关注主题能与 RouteKey 模糊匹配的
队列。</p>
</li>
<li>
<p>这种模式需要 RouteKey，也需要提前绑定 Exchange 与 Queue。</p>
</li>
<li>
<p>在进行绑定时，要提供一个该队列关心的主题，如“#.log.#”表示该队列关心所有涉及
log 的消息(一个 RouteKey 为”MQ.log.error”的消息会被转发到该队列)。
“#”表示 0 个或若干个关键字，“”表示一个关键字。如“log.”能与“log.warn”匹配，
无法与“log.warn.timeout”匹配；但是“log.#”能与上述两者匹配。</p>
</li>
<li>
<p>同样，如果 Exchange 没有发现能够与 RouteKey 匹配的 Queue，则会抛弃此消息</p>
</li>
</ol>
<h2 id="创建队列与绑定">创建队列与绑定</h2>
<p>新建一个交换器 ，类型选择 topic
<img src="/img/%E4%B8%BB%E9%A2%98%E6%A8%A1%E5%BC%8F1.png" alt="alt 主题模式1">
添加匹配规则，添加后列表如下：
<img src="/img/%E6%B7%BB%E5%8A%A0%E4%B8%BB%E9%A2%98%E5%8C%B9%E9%85%8D%E8%A7%84%E5%88%99.png" alt="alt 添加主题匹配规则">
<img src="/img/%E6%B7%BB%E5%8A%A0%E4%B8%BB%E9%A2%98%E8%A7%84%E5%88%99%E5%90%8E.png" alt="alt 添加主题规则后">
设置匹配主题</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 主题模式1
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">TopicTest</span><span style="color:#000;font-weight:bold">(){</span>

        rabbitTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">convertAndSend</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JeremyTopic&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;Jeremy.SZE&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;匹配单个主题模式&#34;</span><span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 主题二
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span>  <span style="color:#900;font-weight:bold">TopicTest1</span><span style="color:#000;font-weight:bold">(){</span>
        rabbitTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">convertAndSend</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JeremyTopic&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;123.log&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;匹配多个主题模式&#34;</span><span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#3c5d5d;font-weight:bold">@Test</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span>  <span style="color:#900;font-weight:bold">TopicTest2</span><span style="color:#000;font-weight:bold">(){</span>
        rabbitTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">convertAndSend</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;JeremyTopic&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;Jeremy.log&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;匹配单个主题模式&#34;</span><span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>消费者</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#3c5d5d;font-weight:bold">@Component</span>
<span style="color:#3c5d5d;font-weight:bold">@RabbitListener</span><span style="color:#000;font-weight:bold">(</span>queues <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;JeremyFanout&#34;</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">ConsumerTopic1</span> <span style="color:#000;font-weight:bold">{</span>

    <span style="color:#3c5d5d;font-weight:bold">@RabbitHandler</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">JeremyFanoutTest</span><span style="color:#000;font-weight:bold">(</span>String msg<span style="color:#000;font-weight:bold">){</span>

        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;匹配单个主题模式:&#34;</span><span style="color:#000;font-weight:bold">+</span>msg<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="使用阿里云大于发送短信">使用阿里云大于发送短信</h2>
<h3 id="阿里大于简介">阿里大于简介</h3>
<p>  阿里大于是阿里云旗下产品，融合了三大运营商的通信能力，通过将传统通信业务和能力与互联网相结合，创新融合阿里巴巴生态内容，全力为中小企业和开发者提供优质服务阿里大于提供包括短信、语音、流量直充、私密专线、店铺手机号等个性化服务。通过阿里大于打通三大运营商通信能力，全面融合阿里巴巴生态，以开放API及SDK的方式向开发者提供通信和数据服务，更好地支撑企业业务发展和创新服务。</p>
<h2 id="准备工作">准备工作</h2>
<h3 id="注册账户">注册账户</h3>
<p>首先我们先进入“阿里大于”www.alidayu.com(<a href="https://dayu.aliyun.com/">https://dayu.aliyun.com/</a>)<br>
注册账号后，再在手机下载“阿里云”应用，登录，然后进行在线实名认证。<br>
<img src="/img/%E7%82%B9%E5%87%BB%E7%AE%A1%E7%90%86%E5%90%8E%E5%8F%B0.png" alt="alt 点击管理后台">
点击进入控制台：
<img src="/img/%E7%82%B9%E5%87%BB%E7%9F%AD%E4%BF%A1%E6%9C%8D%E5%8A%A1.png" alt="alt 点击短信服务">
点击国内消息
<img src="/img/%E7%82%B9%E5%87%BB%E5%9B%BD%E5%86%85%E6%B6%88%E6%81%AF.png" alt="alt 点击国内消息">
<img src="/img/%E6%B7%BB%E5%8A%A0%E7%AD%BE%E5%90%8D.png" alt="alt 添加签名">
申请模板
<img src="/img/%E7%94%B3%E8%AF%B7%E6%A8%A1%E6%9D%BF.png" alt="alt 申请模板">
<img src="/img/%E6%8F%90%E4%BA%A4%E7%94%B3%E8%AF%B7%E6%A8%A1%E6%9D%BF.png" alt="alt 提交申请模板"></p>
<h2 id="创建accesskeys">创建accesskeys</h2>
<p><img src="/img/%E7%82%B9%E5%87%BBAccessKey.png" alt="alt 点击AccessKey">
<img src="/img/%E7%BB%A7%E7%BB%AD%E4%BD%BF%E7%94%A8.png" alt="alt 继续使用">
<img src="/img/%E5%88%9B%E5%BB%BAAccesskey.png" alt="alt 创建Accesskey"></p>
<h2 id="下载sdk及demo">下载SDK及DEMO</h2>
<p><img src="/img/%E4%B8%8B%E8%BD%BDSDKDEMO.png" alt="alt 下载SDKDEMO">
下载地址：https://help.aliyun.com/document_detail/55359.html</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">  <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 生成验证码
</span><span style="color:#998;font-style:italic">     * @param mobile
</span><span style="color:#998;font-style:italic">     * @return
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@RequestMapping</span><span style="color:#000;font-weight:bold">(</span>value <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;/sendsms/{mobile}&#34;</span><span style="color:#000;font-weight:bold">,</span>method <span style="color:#000;font-weight:bold">=</span> RequestMethod<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">POST</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">public</span> Result <span style="color:#900;font-weight:bold">saveCodeAndMobile</span><span style="color:#000;font-weight:bold">(</span><span style="color:#3c5d5d;font-weight:bold">@PathVariable</span> String mobile<span style="color:#000;font-weight:bold">){</span>

        userService<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">saveCodeAndMobile</span><span style="color:#000;font-weight:bold">(</span>mobile<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">return</span> <span style="color:#000;font-weight:bold">new</span> Result<span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">true</span><span style="color:#000;font-weight:bold">,</span>StatusCode<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">OK</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;保存验证码和手机号成功&#34;</span><span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 添加手机号和验证码到MQ及Redis
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">saveCodeAndMobile</span><span style="color:#000;font-weight:bold">(</span>String mobile<span style="color:#000;font-weight:bold">){</span>

        <span style="color:#998;font-style:italic">//生成验证码
</span><span style="color:#998;font-style:italic"></span>        String randomCode <span style="color:#000;font-weight:bold">=</span> RandomStringUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">randomNumeric</span><span style="color:#000;font-weight:bold">(</span>6<span style="color:#000;font-weight:bold">);</span>

        redisTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">opsForValue</span><span style="color:#000;font-weight:bold">().</span><span style="color:#008080">set</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;smsCode_&#34;</span><span style="color:#000;font-weight:bold">+</span>mobile<span style="color:#000;font-weight:bold">,</span>randomCode<span style="color:#000;font-weight:bold">,</span>5<span style="color:#000;font-weight:bold">,</span> TimeUnit<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">MINUTES</span><span style="color:#000;font-weight:bold">);</span>
        Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span>Object<span style="color:#000;font-weight:bold">&gt;</span> map<span style="color:#000;font-weight:bold">=</span><span style="color:#000;font-weight:bold">new</span> HashMap<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;();</span>
        map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;code&#34;</span><span style="color:#000;font-weight:bold">,</span>randomCode<span style="color:#000;font-weight:bold">);</span>
        map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;mobile&#34;</span><span style="color:#000;font-weight:bold">,</span>mobile<span style="color:#000;font-weight:bold">);</span>
        rabbitTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">convertAndSend</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;sms&#34;</span><span style="color:#000;font-weight:bold">,</span>map<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>注册用户</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 注册
</span><span style="color:#998;font-style:italic">     * @param user
</span><span style="color:#998;font-style:italic">     * @param code
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@RequestMapping</span><span style="color:#000;font-weight:bold">(</span>value <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;/register/{code}&#34;</span><span style="color:#000;font-weight:bold">,</span>method <span style="color:#000;font-weight:bold">=</span> RequestMethod<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">POST</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">public</span> Result <span style="color:#900;font-weight:bold">register</span><span style="color:#000;font-weight:bold">(</span><span style="color:#3c5d5d;font-weight:bold">@RequestBody</span> User user<span style="color:#000;font-weight:bold">,</span> <span style="color:#3c5d5d;font-weight:bold">@PathVariable</span> String code<span style="color:#000;font-weight:bold">){</span>
         <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>code<span style="color:#000;font-weight:bold">==</span><span style="color:#000;font-weight:bold">null</span><span style="color:#000;font-weight:bold">||</span><span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">equals</span><span style="color:#000;font-weight:bold">(</span>code<span style="color:#000;font-weight:bold">)){</span>
        <span style="color:#000;font-weight:bold">return</span> <span style="color:#000;font-weight:bold">new</span> Result<span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">false</span><span style="color:#000;font-weight:bold">,</span>StatusCode<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">ERROR</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;请输入验证码&#34;</span><span style="color:#000;font-weight:bold">);</span>

         <span style="color:#000;font-weight:bold">}</span>
        String rediscode<span style="color:#000;font-weight:bold">=(</span>String<span style="color:#000;font-weight:bold">)</span> redisTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">opsForValue</span><span style="color:#000;font-weight:bold">().</span><span style="color:#008080">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;smsCode_&#34;</span><span style="color:#000;font-weight:bold">+</span>user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getMobile</span><span style="color:#000;font-weight:bold">());</span>
         <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>rediscode<span style="color:#000;font-weight:bold">==</span><span style="color:#000;font-weight:bold">null</span> <span style="color:#000;font-weight:bold">||</span> <span style="color:#000;font-weight:bold">!</span>rediscode<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">equals</span><span style="color:#000;font-weight:bold">(</span>code<span style="color:#000;font-weight:bold">)){</span>

        <span style="color:#000;font-weight:bold">return</span> <span style="color:#000;font-weight:bold">new</span> Result<span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">false</span><span style="color:#000;font-weight:bold">,</span>StatusCode<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">ERROR</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;您输入的验证码不对&#34;</span><span style="color:#000;font-weight:bold">);</span>
         <span style="color:#000;font-weight:bold">}</span>

           userService<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">register</span><span style="color:#000;font-weight:bold">(</span>user<span style="color:#000;font-weight:bold">);</span>

        <span style="color:#000;font-weight:bold">return</span> <span style="color:#000;font-weight:bold">new</span> Result<span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">true</span><span style="color:#000;font-weight:bold">,</span>StatusCode<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">OK</span><span style="color:#000;font-weight:bold">,</span><span style="color:#d14">&#34;注册成功&#34;</span><span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java">
    <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 注册
</span><span style="color:#998;font-style:italic">     * @param user
</span><span style="color:#998;font-style:italic">     *
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span>  <span style="color:#900;font-weight:bold">register</span><span style="color:#000;font-weight:bold">(</span>User user<span style="color:#000;font-weight:bold">){</span>

        user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setId</span><span style="color:#000;font-weight:bold">(</span>idWorker<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">nextId</span><span style="color:#000;font-weight:bold">()+</span><span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">);</span>
        user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setRegdate</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">new</span> Date<span style="color:#000;font-weight:bold">());</span>
        user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setFanscount</span><span style="color:#000;font-weight:bold">(</span>0<span style="color:#000;font-weight:bold">);</span>
        user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setFollowcount</span><span style="color:#000;font-weight:bold">(</span>0<span style="color:#000;font-weight:bold">);</span>
        userDao<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">save</span><span style="color:#000;font-weight:bold">(</span>user<span style="color:#000;font-weight:bold">);</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>短信监听</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">55
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">package</span> <span style="color:#555">com.tensquare.sms.listener</span><span style="color:#000;font-weight:bold">;</span>

<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.rabbitmq.client.Channel</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.tensquare.sms.until.SmsUtil</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.amqp.core.Message</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.amqp.rabbit.annotation.RabbitHandler</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.amqp.rabbit.annotation.RabbitListener</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.beans.factory.annotation.Autowired</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.beans.factory.annotation.Value</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.stereotype.Component</span><span style="color:#000;font-weight:bold">;</span>

<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">java.util.Map</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic"> * 短信监听
</span><span style="color:#998;font-style:italic"> */</span>
<span style="color:#3c5d5d;font-weight:bold">@Component</span>
<span style="color:#3c5d5d;font-weight:bold">@RabbitListener</span><span style="color:#000;font-weight:bold">(</span>queues <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;sms&#34;</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">SmsListener</span> <span style="color:#000;font-weight:bold">{</span>

    <span style="color:#3c5d5d;font-weight:bold">@Autowired</span>
    <span style="color:#000;font-weight:bold">private</span> SmsUtil smsUtil<span style="color:#000;font-weight:bold">;</span>

    <span style="color:#3c5d5d;font-weight:bold">@Value</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;${aliyun.sms.temp_code}&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String tempCode<span style="color:#000;font-weight:bold">;</span>

    <span style="color:#3c5d5d;font-weight:bold">@Value</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;${aliyun.sms.sign_name}&#34;</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#000;font-weight:bold">private</span> String signName<span style="color:#000;font-weight:bold">;</span>

    <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 处理方法
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#3c5d5d;font-weight:bold">@RabbitHandler</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">handleMsg</span><span style="color:#000;font-weight:bold">(</span>Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span>String<span style="color:#000;font-weight:bold">&gt;</span> msg<span style="color:#000;font-weight:bold">,</span> Channel channel<span style="color:#000;font-weight:bold">,</span> Message message<span style="color:#000;font-weight:bold">){</span>
        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;手机号码：&#34;</span><span style="color:#000;font-weight:bold">+</span>msg<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;mobile&#34;</span><span style="color:#000;font-weight:bold">));</span>
        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;验证码：&#34;</span><span style="color:#000;font-weight:bold">+</span>msg<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;code&#34;</span><span style="color:#000;font-weight:bold">));</span>

        <span style="color:#998;font-style:italic">//使用阿里云短信发送手机验证码
</span><span style="color:#998;font-style:italic"></span>        <span style="color:#000;font-weight:bold">try</span> <span style="color:#000;font-weight:bold">{</span>
            SendSmsResponse sendSmsResponse <span style="color:#000;font-weight:bold">=</span> smsUtil<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">sendSms</span><span style="color:#000;font-weight:bold">(</span>msg<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;mobile&#34;</span><span style="color:#000;font-weight:bold">),</span> tempCode<span style="color:#000;font-weight:bold">,</span> signName<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;{\&#34;code\&#34;:\&#34;&#34;</span> <span style="color:#000;font-weight:bold">+</span> msg<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;code&#34;</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;\&#34;}&#34;</span><span style="color:#000;font-weight:bold">);</span>

            <span style="color:#000;font-weight:bold">if</span><span style="color:#000;font-weight:bold">(</span>sendSmsResponse<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getCode</span><span style="color:#000;font-weight:bold">().</span><span style="color:#008080">equals</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;OK&#34;</span><span style="color:#000;font-weight:bold">)){</span>
                System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;短信发送成功&#34;</span><span style="color:#000;font-weight:bold">);</span>
                <span style="color:#998;font-style:italic">//手动发送确认消息给MQ，让MQ删除对应的消息
</span><span style="color:#998;font-style:italic"></span>                channel<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">basicAck</span><span style="color:#000;font-weight:bold">(</span>message<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getMessageProperties</span><span style="color:#000;font-weight:bold">().</span><span style="color:#008080">getDeliveryTag</span><span style="color:#000;font-weight:bold">(),</span><span style="color:#000;font-weight:bold">false</span><span style="color:#000;font-weight:bold">);</span>
            <span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">else</span><span style="color:#000;font-weight:bold">{</span>
                System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;短信发送失败：&#34;</span><span style="color:#000;font-weight:bold">+</span>sendSmsResponse<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getCode</span><span style="color:#000;font-weight:bold">());</span>
            <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">catch</span> <span style="color:#000;font-weight:bold">(</span>Exception e<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
            e<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">printStackTrace</span><span style="color:#000;font-weight:bold">();</span>
        <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">}</span>

<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>短信工具类</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">  9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 62
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 63
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 64
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 65
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 66
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 67
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 68
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 69
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 70
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 71
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 72
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 73
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 74
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 75
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 76
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 77
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 78
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 79
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 80
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 81
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 82
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 83
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 84
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 85
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 86
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 87
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 88
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 89
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 90
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 91
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 92
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 93
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 94
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 95
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 96
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 97
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 98
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 99
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">100
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">package</span> <span style="color:#555">com.tensquare.sms.until</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.DefaultAcsClient</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.IAcsClient</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.exceptions.ClientException</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.profile.DefaultProfile</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">com.aliyuncs.profile.IClientProfile</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.beans.factory.annotation.Autowired</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.core.env.Environment</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">org.springframework.stereotype.Component</span><span style="color:#000;font-weight:bold">;</span>

<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">java.text.SimpleDateFormat</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">import</span> <span style="color:#555">java.util.Date</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic"> * 短信工具类
</span><span style="color:#998;font-style:italic"> * @author Administrator
</span><span style="color:#998;font-style:italic"> *
</span><span style="color:#998;font-style:italic"> */</span>
<span style="color:#3c5d5d;font-weight:bold">@Component</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">SmsUtil</span> <span style="color:#000;font-weight:bold">{</span>

    <span style="color:#998;font-style:italic">//产品名称:云通信短信API产品,开发者无需替换
</span><span style="color:#998;font-style:italic"></span>    <span style="color:#000;font-weight:bold">static</span> <span style="color:#000;font-weight:bold">final</span> String product <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;Dysmsapi&#34;</span><span style="color:#000;font-weight:bold">;</span>
    <span style="color:#998;font-style:italic">//产品域名,开发者无需替换
</span><span style="color:#998;font-style:italic"></span>    <span style="color:#000;font-weight:bold">static</span> <span style="color:#000;font-weight:bold">final</span> String domain <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;dysmsapi.aliyuncs.com&#34;</span><span style="color:#000;font-weight:bold">;</span>

    <span style="color:#3c5d5d;font-weight:bold">@Autowired</span>
    <span style="color:#000;font-weight:bold">private</span> Environment env<span style="color:#000;font-weight:bold">;</span>

    <span style="color:#998;font-style:italic">// TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
</span><span style="color:#998;font-style:italic"></span>
    <span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">     * 发送短信
</span><span style="color:#998;font-style:italic">     * @param mobile 手机号
</span><span style="color:#998;font-style:italic">     * @param template_code 模板号
</span><span style="color:#998;font-style:italic">     * @param sign_name 签名
</span><span style="color:#998;font-style:italic">     * @param param 参数
</span><span style="color:#998;font-style:italic">     * @return
</span><span style="color:#998;font-style:italic">     * @throws ClientException
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#000;font-weight:bold">public</span> SendSmsResponse <span style="color:#900;font-weight:bold">sendSms</span><span style="color:#000;font-weight:bold">(</span>String mobile<span style="color:#000;font-weight:bold">,</span>String template_code<span style="color:#000;font-weight:bold">,</span>String sign_name<span style="color:#000;font-weight:bold">,</span>String param<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">throws</span> ClientException <span style="color:#000;font-weight:bold">{</span>
        String accessKeyId <span style="color:#000;font-weight:bold">=</span>env<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;aliyun.sms.accessKeyId&#34;</span><span style="color:#000;font-weight:bold">);</span>
        String accessKeySecret <span style="color:#000;font-weight:bold">=</span> env<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;aliyun.sms.accessKeySecret&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//可自助调整超时时间
</span><span style="color:#998;font-style:italic"></span>        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;sun.net.client.defaultConnectTimeout&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;10000&#34;</span><span style="color:#000;font-weight:bold">);</span>
        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;sun.net.client.defaultReadTimeout&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;10000&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//初始化acsClient,暂不支持region化
</span><span style="color:#998;font-style:italic"></span>        IClientProfile profile <span style="color:#000;font-weight:bold">=</span> DefaultProfile<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getProfile</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;cn-hangzhou&#34;</span><span style="color:#000;font-weight:bold">,</span> accessKeyId<span style="color:#000;font-weight:bold">,</span> accessKeySecret<span style="color:#000;font-weight:bold">);</span>
        DefaultProfile<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">addEndpoint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;cn-hangzhou&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;cn-hangzhou&#34;</span><span style="color:#000;font-weight:bold">,</span> product<span style="color:#000;font-weight:bold">,</span> domain<span style="color:#000;font-weight:bold">);</span>
        IAcsClient acsClient <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> DefaultAcsClient<span style="color:#000;font-weight:bold">(</span>profile<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//组装请求对象-具体描述见控制台-文档部分内容
</span><span style="color:#998;font-style:italic"></span>        SendSmsRequest request <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> SendSmsRequest<span style="color:#000;font-weight:bold">();</span>
        <span style="color:#998;font-style:italic">//必填:待发送手机号
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setPhoneNumbers</span><span style="color:#000;font-weight:bold">(</span>mobile<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//必填:短信签名-可在短信控制台中找到
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setSignName</span><span style="color:#000;font-weight:bold">(</span>sign_name<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//必填:短信模板-可在短信控制台中找到
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setTemplateCode</span><span style="color:#000;font-weight:bold">(</span>template_code<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//可选:模板中的变量替换JSON串,如模板内容为&#34;亲爱的${name},您的验证码为${code}&#34;时,此处的值为
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setTemplateParam</span><span style="color:#000;font-weight:bold">(</span>param<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//选填-上行短信扩展码(无特殊需求用户请忽略此字段)
</span><span style="color:#998;font-style:italic"></span>        <span style="color:#998;font-style:italic">//request.setSmsUpExtendCode(&#34;90997&#34;);
</span><span style="color:#998;font-style:italic"></span>        <span style="color:#998;font-style:italic">//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setOutId</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;yourOutId&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//hint 此处可能会抛出异常，注意catch
</span><span style="color:#998;font-style:italic"></span>        SendSmsResponse sendSmsResponse <span style="color:#000;font-weight:bold">=</span> acsClient<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getAcsResponse</span><span style="color:#000;font-weight:bold">(</span>request<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">return</span> sendSmsResponse<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#000;font-weight:bold">public</span>  QuerySendDetailsResponse <span style="color:#900;font-weight:bold">querySendDetails</span><span style="color:#000;font-weight:bold">(</span>String mobile<span style="color:#000;font-weight:bold">,</span>String bizId<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">throws</span> ClientException <span style="color:#000;font-weight:bold">{</span>
        String accessKeyId <span style="color:#000;font-weight:bold">=</span>env<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;accessKeyId&#34;</span><span style="color:#000;font-weight:bold">);</span>
        String accessKeySecret <span style="color:#000;font-weight:bold">=</span> env<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;accessKeySecret&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//可自助调整超时时间
</span><span style="color:#998;font-style:italic"></span>        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;sun.net.client.defaultConnectTimeout&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;10000&#34;</span><span style="color:#000;font-weight:bold">);</span>
        System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setProperty</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;sun.net.client.defaultReadTimeout&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;10000&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//初始化acsClient,暂不支持region化
</span><span style="color:#998;font-style:italic"></span>        IClientProfile profile <span style="color:#000;font-weight:bold">=</span> DefaultProfile<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getProfile</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;cn-hangzhou&#34;</span><span style="color:#000;font-weight:bold">,</span> accessKeyId<span style="color:#000;font-weight:bold">,</span> accessKeySecret<span style="color:#000;font-weight:bold">);</span>
        DefaultProfile<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">addEndpoint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;cn-hangzhou&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;cn-hangzhou&#34;</span><span style="color:#000;font-weight:bold">,</span> product<span style="color:#000;font-weight:bold">,</span> domain<span style="color:#000;font-weight:bold">);</span>
        IAcsClient acsClient <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> DefaultAcsClient<span style="color:#000;font-weight:bold">(</span>profile<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//组装请求对象
</span><span style="color:#998;font-style:italic"></span>        QuerySendDetailsRequest request <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> QuerySendDetailsRequest<span style="color:#000;font-weight:bold">();</span>
        <span style="color:#998;font-style:italic">//必填-号码
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setPhoneNumber</span><span style="color:#000;font-weight:bold">(</span>mobile<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//可选-流水号
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setBizId</span><span style="color:#000;font-weight:bold">(</span>bizId<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//必填-发送日期 支持30天内记录查询，格式yyyyMMdd
</span><span style="color:#998;font-style:italic"></span>        SimpleDateFormat ft <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> SimpleDateFormat<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;yyyyMMdd&#34;</span><span style="color:#000;font-weight:bold">);</span>
        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setSendDate</span><span style="color:#000;font-weight:bold">(</span>ft<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">format</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">new</span> Date<span style="color:#000;font-weight:bold">()));</span>
        <span style="color:#998;font-style:italic">//必填-页大小
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setPageSize</span><span style="color:#000;font-weight:bold">(</span>10L<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//必填-当前页码从1开始计数
</span><span style="color:#998;font-style:italic"></span>        request<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCurrentPage</span><span style="color:#000;font-weight:bold">(</span>1L<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">//hint 此处可能会抛出异常，注意catch
</span><span style="color:#998;font-style:italic"></span>        QuerySendDetailsResponse querySendDetailsResponse <span style="color:#000;font-weight:bold">=</span> acsClient<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getAcsResponse</span><span style="color:#000;font-weight:bold">(</span>request<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">return</span> querySendDetailsResponse<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div>
        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://laoer123.gitee.io/laoer123">Jeremy Sze</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://laoer123.gitee.io/laoer123/post/RabbitMQ%E6%80%BB%E7%BB%93/">https://laoer123.gitee.io/laoer123/post/RabbitMQ%E6%80%BB%E7%BB%93/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/laoer123/post/ElasticSearch/">ElasticSearch总结</a></li>
        
        <li><a href="/laoer123/post/MongoDB%E6%80%BB%E7%BB%93/">MongoDB总结</a></li>
        
        <li><a href="/laoer123/post/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E4%B8%BA%E4%BB%80%E4%B9%88%E4%B8%8D%E7%94%A8%E5%86%99%E6%8E%A5%E5%8F%A3/">微服务为什么不用写接口</a></li>
        
        <li><a href="/laoer123/post/springdataredis%E4%B8%8EspringCache%E5%8C%BA%E5%88%AB/">springdataredis与springCache区别</a></li>
        
        <li><a href="/laoer123/post/Linux%E5%AD%A6%E4%B9%A0/">Linux学习总结</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='https://laoer123.gitee.io/tags/RabbitMQ'>RabbitMQ</a></li>
                
            </ul>
            
        </div>
    </article>
    
    <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "yourdiscussshortname" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

    
    
</div>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://laoer123.gitee.io/laoer123/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://laoer123.gitee.io/laoer123">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/springcloud%E4%B8%8EspringcloudAlibaba%E6%80%BB%E7%BB%93/" title="springcloud与springcloudAlibaba总结">springcloud与springcloudAlibaba总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Seata%E6%80%BB%E7%BB%93/" title="Seata总结">Seata总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/OpenFegin%E6%80%BB%E7%BB%93/" title="OpenFegin总结">OpenFegin总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudGateWay%E6%80%BB%E7%BB%93/" title="SpringCloudGateWay总结">SpringCloudGateWay总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudRibbon/" title="SpringCloudRibbon总结">SpringCloudRibbon总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E6%B3%A8%E5%86%8C%E4%B8%8E%E5%8F%91%E7%8E%B0/" title="Nacos配置注册与发现">Nacos配置注册与发现</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86%E6%BC%94%E7%A4%BA/" title="Nacos配置管理演示">Nacos配置管理演示</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E6%80%BB%E7%BB%93/" title="什么是Nacos">什么是Nacos</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%96%B0%E6%89%8B%E6%8C%87%E5%8D%97/" title="Sentinel新手指南">Sentinel新手指南</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%8E%A7%E5%88%B6%E5%8F%B0/" title="Sentinel控制台">Sentinel控制台</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">分类</h3>
<ul class="widget-list">
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/Linux/">Linux (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/NoSql%E6%95%B0%E6%8D%AE%E5%BA%93/">NoSql数据库 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloud/">SpringCloud (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibaba/">SpringCloudAlibaba (11)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibabaSpringCloud/">SpringCloudAlibaba,SpringCloud (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/docker/">docker (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/java%E5%9F%BA%E7%A1%80/">java基础 (10)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/spring/">spring (4)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E4%BA%8B%E5%8A%A1/">事务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E5%BE%AE%E6%9C%8D%E5%8A%A1/">前端微服务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E6%A1%86%E6%9E%B6/">前端框架 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90/">持续集成 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/">搜索引擎 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%B1%82%E6%A1%86%E6%9E%B6/">数据层框架 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库 (5)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/">服务器 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9E%B6%E6%9E%84/">架构 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/">消息中间件 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%BC%93%E5%AD%98/">缓存 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%AE%A4%E8%AF%81/">认证 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%BF%90%E7%BB%B4/">运维 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E9%83%A8%E7%BD%B2/">部署 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title">标签</h3>
<div class="tagcloud">
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Dubbo/">Dubbo</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ES6/">ES6</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElasticSearch/">ElasticSearch</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElementUI/">ElementUI</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Eureka/">Eureka</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Feign/">Feign</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JDBCTemplate/">JDBCTemplate</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JPA/">JPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JWT/">JWT</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Jenkins/">Jenkins</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E5%9F%BA%E7%A1%80/">Linux基础</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E9%85%8D%E7%BD%AE%E8%81%94%E7%BD%91/">Linux配置联网</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/MongoDB/">MongoDB</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Nacos/">Nacos</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ORACLE/">ORACLE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/OpenFegin/">OpenFegin</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/RabbitMQ/">RabbitMQ</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Seata/">Seata</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Sentinel/">Sentinel</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudGateWay/">SpringCloudGateWay</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudRibbon/">SpringCloudRibbon</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudSpringCloudAlibaba/">SpringCloud,SpringCloudAlibaba</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/VUE/">VUE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/docker/">docker</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/git/">git</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/gogs/">gogs</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/hystrix/">hystrix</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/mysql/">mysql</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nginx/">nginx</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nodeJS/">nodeJS</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/npm/">npm</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springCache/">springCache</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springDataJPA/">springDataJPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springboot/">springboot</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudbus/">springcloudbus</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudconfig/">springcloudconfig</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springdataredis/">springdataredis</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/zuul/">zuul</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E4%BA%8B%E5%8A%A1/">分布式事务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%9B%E5%BB%BA%E6%A8%A1%E5%BC%8F/">创建模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%BE%AE%E6%9C%8D%E5%8A%A1/">微服务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%8E%92%E5%BA%8F/">排序</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%9C%8D%E5%8A%A1%E9%95%9C%E5%83%8F%E7%9A%84%E6%9E%84%E5%BB%BA%E4%B8%8E%E9%83%A8%E7%BD%B2/">服务镜像的构建与部署</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E7%BB%93%E6%9E%84%E6%A8%A1%E5%BC%8F/">结构模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%A1%8C%E4%B8%BA%E6%A8%A1%E5%BC%8F/">行为模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">设计模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%BF%90%E7%BB%B4/">运维</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://www.cnblogs.com/Jeremy95-Sze/" title="Jeremy Sze的博客">Jeremy Sze的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://github.com/Jeremy95-Sze" title="Jeremy Sze的github">Jeremy Sze的github</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://laoer123.gitee.io/laoer123/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
    <footer id="footer">
    <div class="container">
        &copy; 2023 <a href="https://laoer123.gitee.io/laoer123">Jeremy Sze的博客 By Jeremy Sze</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="https://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/flysnow-org/maupassant-hugo" target="_blank">maupassant</a>.
        
    </div>
</footer>


    
    <script src="//cdnjs.cloudflare.com/ajax/libs/webfont/1.6.28/webfontloader.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js" crossorigin="anonymous"></script>
        <script>(function () {
            if (!window.Diagram) return;
            const blocks = document.querySelectorAll('pre code.language-sequence');
            for (let i = 0; i < blocks.length; i++) {
                const block = blocks[i];
                
                const rootElement = block.parentNode;
                const container = document.createElement('div');
                const id = `js-sequence-diag-${i}`;
                container.id = id;
                container.className = 'align-center';
                container.setAttribute("style", "overFlow-x:auto");
                rootElement.parentNode.replaceChild(container, rootElement);

                const diagram = Diagram.parse(block.childNodes[0].nodeValue);
                diagram.drawSVG(id, window.sequenceDiagramsOptions
                    ? window.sequenceDiagramsOptions
                    : { theme: 'simple' });
            }
        })();
        </script><script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>


<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/laoer123/js/totop.js?v=0.0.0' async=""></script>

<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'GA ID', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/laoer123/js/douban.js'></script>

</body>

</html>